package com.wzh.glsc.oss.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.thymeleaf.util.StringUtils;

import javax.servlet.http.HttpSession;

/**
 * @author xiaoming
 * @PackageName:com.wzh.glsc.oss.controller
 * @ClassName:@{NAME}
 * @Description:
 * @date:@{DATE}@{TIME}
 */
@Controller
public class Login2Controller {

    @Autowired
    StringRedisTemplate redisTemplate;

    @RequestMapping("/index")
    public String index(
            String token
            , HttpSession session) {
        if (!StringUtils.isEmpty(token)) {
            String name = redisTemplate.opsForValue().get(token);
            session.setAttribute("name", name);
            return "index";
        }
        if (session.getAttribute("name") == null) {
            return "redirect:http://oss.login.com:1811/login?url=http://oss.admin.com:1812/index";
        }
        return "index";
    }
}
